﻿using System;

namespace Samurai.Workflow
{
    public interface IWorkflowStep<T> where T : class, IWorkflowContext 
    {
        /// <summary>
        /// Occurs when the workflow step is completed.
        /// </summary>
        event EventHandler<WorkflowStepCompletedEventArgs<T>> Completed;

        /// <summary>
        /// Occurs when the workflow step has failed execution.
        /// </summary>
        event EventHandler<WorkflowStepCompletedEventArgs<T>> Failed;

        /// <summary>
        /// Gets or sets the context that is shared among all steps in the workflow.
        /// </summary>
        /// <value>The context.</value>
        T Context { get; set; }

        /// <summary>
        /// Gets or sets the thread on which to execute this step.
        /// </summary>
        /// <value>The thread.</value>
        ThreadType Thread { get; set; }

        /// <summary>
        /// Gets or sets the workflow in which this step is to execute.
        /// </summary>
        /// <value>The workflow.</value>
        IWorkflow<T> Workflow { get; set; }

        /// <summary>
        /// Gets a value indicating whether this instance has completed.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance has completed; otherwise, <c>false</c>.
        /// </value>
        bool HasCompleted { get; }

        /// <summary>
        /// Gets or sets a value indicating whether to halt workflow on the failure of this step.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [halt workflow on failure]; otherwise, <c>false</c>.
        /// </value>
        bool IsCritical { get; set; }

        /// <summary>
        /// Executes the step.
        /// </summary>
        void ExecuteStep();
    }
}
